﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using SchoolSystem.DAL;
using System.Data.Entity;

namespace SchoolSystem.UI.WindowsForms
{
    public partial class Form1 : Form
    {
        private SchoolSystemDbEntities _db;

        public Form1()
        {
            InitializeComponent();
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            _db.SaveChanges();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _db = new SchoolSystemDbEntities();
            addressBindingSource.DataSource = _db.Addresses.Local.ToBindingList();
            countryBindingSource.DataSource = _db.Countries.ToList();

            
        }

        private void addressBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            _db.SaveChanges();
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            this._db.Dispose();
        }
    }
}
